package com.coffee.rocketmq;

import lombok.extern.slf4j.Slf4j;

/**
 * public   abstract class AbstractMochaRocketMQConsumer<T extends MochaMQMessage<?>>  implements RocketMQListener<T>
 *     这样 会报错 ： parameterType:T of onMessage method is not supported
 * @author songkui
 * @since 2024/2/27 15:01
 */
@Slf4j
public abstract class AbstractMochaRocketMQConsumer<T extends MochaMQMessage<?>> {

    /**
     * 处理消息
     *
     * @param message
     */
    public void onMochaMessage(T message) {
        if (isConsumedMessage(message)) {
            log.warn("The message has been consumed, key: {}", message.getKey());
            return;
        }
        consumeMessage(message);
    }


    /**
     * 是否 消费
     *
     * @param message
     * @return true 表已经消费该消息， false 还未消费
     */
    protected abstract boolean isConsumedMessage(T message);

    /**
     * 处理消息
     *
     * @param message
     */
    protected abstract void consumeMessage(T message);


}
